home *** CD-ROM | disk | FTP | other *** search
- unit uMobileAgentUI;
-
- {
- *******************************************************************************
- * Descriptions: COM/Script Interface implementation
- * $Source: /cvsroot/fma/fma/uMobileAgentUI.pas,v $
- * $Locker: $
- *
- * Todo:
- *
- * Change Log:
- * $Log: uMobileAgentUI.pas,v $
- * Revision 1.14 2004/06/28 09:14:06 z_stoichev
- * - Added 912934 Add fma.PhoneType method (MHWFO).
- * - Added 972252 Add fma.DisconnectTemporary (autoconnect).
- *
- * Revision 1.13 2004/06/08 19:20:31 lordlarry
- * Memory Leak fixed
- *
- * Revision 1.12 2004/03/20 16:26:17 z_stoichev
- * Added fma.ScriptCall(code) COMObject method.
- * Added fma.Sleep(msec) COMObject method.
- *
- * Revision 1.11 2004/02/04 13:01:23 z_stoichev
- * Add object methods call support.
- *
- * Revision 1.10 2004/02/03 16:28:08 z_stoichev
- * Added new methods, TxAndWait synced with Form1.
- *
- * Revision 1.9 2004/01/30 16:37:08 z_stoichev
- * Added ObexCut method.
- * Made ObexDelete work in silent mode.
- *
- * Revision 1.8 2004/01/27 15:50:33 z_stoichev
- * Changed method definitions (removed 'success' out)
- * Added ObexGet and ObexDelete (for files).
- *
- * Revision 1.7 2004/01/23 08:30:51 z_stoichev
- * Fixed Transmit function
- *
- * Revision 1.6 2003/12/18 12:45:15 z_stoichev
- * ObexGetObj and ObexPutObj implemented.
- *
- * Revision 1.5 2003/11/28 09:38:07 z_stoichev
- * Merged with branch-release-1-1 (Fma 0.10.28c)
- *
- * Revision 1.4.2.1 2003/10/27 07:22:54 z_stoichev
- * Build 0.1.0 RC1 Initial Checkin.
- *
- * Revision 1.4 2003/02/14 11:34:52 crino77
- * Added StatusReq in SentMessage
- *
- * Revision 1.3 2003/01/30 04:15:57 warren00
- * Updated with header comments
- *
- *
- *******************************************************************************
- }
-
- {$WARN SYMBOL_PLATFORM OFF}
-
- interface
-
- uses
- ComObj, ActiveX, MobileAgent_TLB, StdVcl, Classes, Menus, ExtCtrls;
-
- type
- TMobileAgentApp = class(TAutoObject, IMobileAgentApp)
- private
- sl: TStrings;
- tl: TStrings;
- rootMenu: TMenuItem;
- protected
- procedure AddCmd(const label_, event: WideString); safecall;
- procedure Connect; safecall;
- procedure Disconnect; safecall;
- procedure Exit; safecall;
- function Get_KeyPress: WideString; safecall;
- function Get_PopKey: WideString; safecall;
- procedure Debug(const str: WideString); safecall;
- procedure ClearKey; safecall;
- procedure Status(const Str: WideString); safecall;
- procedure Minimize; safecall;
- procedure Restore; safecall;
- procedure Set_KeyInActivityTimeout(Value: Integer); safecall;
- procedure Transmit(const Cmd: WideString); safecall;
- function Get_Connected: Integer; safecall;
- function Get_LookupByNumber(const Number: WideString): WideString;
- safecall;
- function Get_Received: WideString; safecall;
- procedure SentMessage(const Msg, DestNo: WideString; ReqReply,
- Flash, StatusReq: Smallint); safecall;
- procedure ObexPut(const filename: WideString); safecall;
- procedure VoiceAnswer; safecall;
- procedure VoiceCall(const Number: WideString); safecall;
- procedure VoiceHangUp; safecall;
- function ObexGetObj(const filename, objecturl: WideString): HResult;
- safecall;
- function ObexPutObj(const filename, objecturl: WideString): HResult;
- safecall;
- function ObexGet(const filename, objectname: WideString): HResult;
- safecall;
- procedure ObexDelete(const objectname: WideString); safecall;
- function ObexCut(const filename, objectname: WideString): HResult;
- safecall;
- procedure AddTimer(msec: Integer; const event: WideString); safecall;
- procedure DeleteTimer(const event: WideString); safecall;
- procedure EnableKeyMonitor; safecall;
- procedure DisableKeyMonitor; safecall;
- procedure ScriptCall(const Code: WideString); safecall;
- procedure Sleep(msec: Integer); safecall;
- function Get_PhoneType(const Number: WideString): WideString; safecall;
- procedure DisconnectTemporary; safecall;
- { Protected declarations }
- public
- procedure Initialize; override;
- destructor Destroy; override;
- procedure MenuClicked(Sender: TObject);
- procedure TimerEvent(Sender: TObject);
- end;
-
- implementation
-
- uses ComServ, Unit1, SysUtils, Dialogs, uObex, uSyncPhonebook;
-
- var rootCount: integer;
-
- procedure TMobileAgentApp.AddCmd(const label_, event: WideString);
- var
- menuItem: TMenuItem;
- begin
- menuItem := TMenuItem.Create(Form1.MainMenu1);
- menuItem.Caption := label_;
- menuItem.Tag := sl.Count;
- menuItem.OnClick := MenuClicked;
- rootMenu.Add(menuItem);
-
- sl.Add(IntToStr(sl.Count) + '=' + event);
- end;
-
- procedure TMobileAgentApp.Initialize;
- begin
- inherited;
- sl := TStringList.Create;
- tl := TStringList.Create;
-
- with Form1.MainMenu1 do begin
- rootMenu := Items.Find('Tools');
- if rootCount = 0 then rootCount := rootMenu.Count;
- end;
- end;
-
- procedure TMobileAgentApp.MenuClicked(Sender: TObject);
- var
- tag: Integer;
- cmd: String;
- begin
- tag := (Sender as TMenuItem).Tag;
- cmd := sl.Values[IntToStr(tag)];
-
- Form1.CallScriptMethod(cmd,[]);
- end;
-
- procedure TMobileAgentApp.Connect;
- begin
- Form1.ActionConnectionConnect.Execute;
- end;
-
- procedure TMobileAgentApp.Disconnect;
- begin
- Form1.ActionConnectionDisconnect.Execute;
- end;
-
- procedure TMobileAgentApp.Exit;
- begin
- Form1.Close;
- end;
-
- function TMobileAgentApp.Get_KeyPress: WideString;
- begin
- Result := Form1.FKeyActivity;
- end;
-
- function TMobileAgentApp.Get_PopKey: WideString;
- begin
- Result := Copy(Form1.FKeyActivity, length(Form1.FKeyActivity), 1);
- Form1.FKeyActivity := Copy(Form1.FKeyActivity, 1, length(Form1.FKeyActivity) - 1);
- end;
-
- procedure TMobileAgentApp.EnableKeyMonitor;
- begin
- Form1.EnableKeyMonitor(True);
- end;
-
- procedure TMobileAgentApp.Debug(const str: WideString);
- begin
- Form1.Debug('[Script] ' + str);
- end;
-
- procedure TMobileAgentApp.ClearKey;
- begin
- Form1.FKeyActivity := '';
- end;
-
- procedure TMobileAgentApp.Status(const Str: WideString);
- begin
- Form1.Status(Str);
- end;
-
- procedure TMobileAgentApp.Minimize;
- begin
- Form1.MinimizeApp;
- end;
-
- procedure TMobileAgentApp.Restore;
- begin
- Form1.ActionWindowRestore.Execute;
- end;
-
- procedure TMobileAgentApp.Set_KeyInActivityTimeout(Value: Integer);
- begin
- Form1.Debug('KeyInactivityTimeout set to ' + IntToStr(Value) + 'ms');
- Form1.FKeyInactivityTimeout := Value;
- end;
-
- procedure TMobileAgentApp.Transmit(const Cmd: WideString);
- begin
- Form1.ScheduleTxAndWait(Cmd);
- end;
-
- function TMobileAgentApp.Get_Connected: Integer;
- begin
- if Form1.FConnected then Result := 1
- else Result := 0;
- end;
-
- function TMobileAgentApp.Get_LookupByNumber(
- const Number: WideString): WideString;
- begin
- Result := Form1.LookupContact(Number);
- end;
-
- function TMobileAgentApp.Get_Received: WideString;
- begin
- Result := Form1.FRxBuffer.Text;
- end;
-
- procedure TMobileAgentApp.SentMessage(const Msg, DestNo: WideString;
- ReqReply, Flash, StatusReq: Smallint);
- var
- AReqReply, AFlash, AStatusReq: Boolean;
- begin
- if ReqReply = 0 then AReqReply := False
- else AReqReply := True;
-
- if Flash = 0 then AFlash := False
- else AFlash := True;
-
- if StatusReq = 0 then AStatusReq := False
- else AStatusReq := True;
-
- Form1.SentMessage('', Msg, DestNo, AReqReply, AFlash, AStatusReq);
- end;
-
- procedure TMobileAgentApp.ObexPut(const filename: WideString);
- begin
- Form1.ObexPutFile(filename);
- end;
-
- procedure TMobileAgentApp.VoiceAnswer;
- begin
- Form1.VoiceAnswer;
- end;
-
- procedure TMobileAgentApp.VoiceCall(const Number: WideString);
- begin
- Form1.VoiceCall(Number);
- end;
-
- procedure TMobileAgentApp.VoiceHangUp;
- begin
- Form1.VoiceHangUp;
- end;
-
- function TMobileAgentApp.ObexGetObj(const filename,
- objecturl: WideString): HResult;
- var
- fs: TFileStream;
- begin
- Result := 0; // error
- try
- fs := TFileStream.Create(filename,fmCreate);
- try
- with Form1 do begin
- ObexConnect;
- try
- ObexGetObject(objecturl,TStream(fs));
- finally
- ObexDisconnect;
- end;
- end;
- Result := 1;
- finally
- fs.Free;
- end;
- except
- end;
- end;
-
- function TMobileAgentApp.ObexPutObj(const filename,
- objecturl: WideString): HResult;
- var
- fs: TFileStream;
- begin
- Result := 0; // error
- try
- fs := TFileStream.Create(filename,fmOpenRead);
- try
- with Form1 do begin
- ObexConnect;
- try
- ObexPutObject(objecturl,fs);
- finally
- ObexDisconnect;
- end;
- end;
- Result := 1;
- finally
- fs.Free;
- end;
- except
- end;
- end;
-
- function TMobileAgentApp.ObexGet(const filename,
- objectname: WideString): HResult;
- begin
- Result := 0; // error
- try
- Form1.ObexGetFile(filename,objectname,True);
- Result := 1;
- except
- end;
- end;
-
- procedure TMobileAgentApp.ObexDelete(const objectname: WideString);
- begin
- Form1.ObexPutFile(objectname,True,True);
- end;
-
- function TMobileAgentApp.ObexCut(const filename,
- objectname: WideString): HResult;
- begin
- with Form1 do begin
- RequestConnection;
- ObexConnect(ObexFolderBrowserServiceID);
- try
- FObex.GetFile(filename,objectname,True);
- ObexPutFile(objectname,True,True);
- finally
- ObexDisconnect;
- end;
- end;
- end;
-
- procedure TMobileAgentApp.AddTimer(msec: Integer; const event: WideString);
- var
- timer: TTimer;
- begin
- DeleteTimer(event);
- timer := TTimer.Create(nil);
- timer.OnTimer := TimerEvent;
- timer.Interval := msec;
- tl.AddObject(event,timer);
- end;
-
- procedure TMobileAgentApp.TimerEvent(Sender: TObject);
- var
- i: Integer;
- begin
- for i := 0 to tl.Count-1 do
- if tl.Objects[i] = Sender then
- try
- with Sender as TTimer do
- try
- Enabled := False;
-
- Form1.CallScriptMethod(tl[i], []);
- finally
- Enabled := True;
- end;
- break;
- except
- on e: Exception do Debug(e.Message);
- end;
- end;
-
- procedure TMobileAgentApp.DeleteTimer(const event: WideString);
- var
- i: Integer;
- begin
- for i := 0 to tl.Count-1 do
- if WideCompareText(tl[i],event) = 0 then begin
- with tl.Objects[i] as TTimer do begin
- Enabled := False;
- Free;
- end;
- tl.Delete(i);
- break;
- end;
- end;
-
- destructor TMobileAgentApp.Destroy;
- var
- i: Integer;
- begin
- sl.Free;
- tl.Free;
-
- { Remove Timer events }
- for i := tl.Count-1 downto 0 do DeleteTimer(tl[i]);
- { Remove Main menu entries }
- for i := rootMenu.Count-1 downto rootCount do rootMenu.Delete(i);
- inherited;
- end;
-
- procedure TMobileAgentApp.DisableKeyMonitor;
- begin
- Form1.DisableKeyMonitor(True);
- end;
-
- procedure TMobileAgentApp.ScriptCall(const Code: WideString);
- begin
- Form1.ScriptControl.CallFunction(__fma_objcall,[Code]);
- end;
-
- procedure TMobileAgentApp.Sleep(msec: Integer);
- begin
- WaitASec(msec,True);
- end;
-
- function TMobileAgentApp.Get_PhoneType(
- const Number: WideString): WideString;
- var
- contact: PContactData;
- FullName: WideString;
- begin
- Result := ''; // unknown
- if Form1.FUseObex and not Form1.FStartupOptions.NoIRMC then begin
- FullName := Form1.LookupContact(Number);
- if (FullName <> '') and Form1.frmSyncPhonebook.FindContact(FullName,contact) then
- Result := GetContactPhoneType(contact,Number);
- end;
- end;
-
- procedure TMobileAgentApp.DisconnectTemporary;
- begin
- Form1.DoDisconnectTemporary;
- end;
-
- initialization
- rootCount := 0;
- TAutoObjectFactory.Create(ComServer, TMobileAgentApp, Class_MobileAgentApp,
- ciMultiInstance, tmSingle);
- end.
-